﻿namespace Socium.Science {
	struct Range {
		private readonly double _from;
		private readonly double _to;

		public Range(double a, double b) {
			if (a > b) {
				_from = b;
				_to = a;
			}
			else {
				_from = a;
				_to = b;
			}
		}

		public bool Contains(double value) {
			return value >= _from && value <= _to;
		}

		public override string ToString() {
			return string.Format("[{0}, {1}]", _from, _to);
		}

		public double LimitValue(double value) {
			if (value < _from) {
				return _from;
			}

			if (value > _to) {
				return _to;
			}

			return value;
		}
	}
}
